#include <REGX52.H>
#include "LCD1602.h"
#include "MatrixKey.h"

  unsigned char KeyNum=0;
  unsigned int count=0;
  unsigned int PassWord=0;

void main()
{ 
	LCD_Init();
	LCD_ShowString(1,1,"PassWord");
	
		while(1)
		{
			KeyNum=Matrixkey();
			if(KeyNum)	
			{
				if(KeyNum<=10)  //按下s1~s10,输入密码
				{
					if(count<4)   //如果输入次数小于4
					{
						PassWord*=10;    //密码左移
						PassWord+=KeyNum%10;  //输入一位密码
						count++;              //计数加一
					}
				LCD_ShowNum(2,1,PassWord,4);   //更新显示
				}
		
				if(KeyNum==11)    //确认密码
				{
					if(PassWord==1314)   
					{
						LCD_ShowString(1,11,"GOOD");   //密码正确
					PassWord=0;                   //密码清零
					count=0;                     //计数清零
					                   
				LCD_ShowNum(2,1,PassWord,4);   //更新显示
				}
				else
				{
					LCD_ShowString(1,11,"2B  ");
					PassWord=0;
					count=0;
					LCD_ShowNum(2,1,PassWord,4);   //更新显示
				}
				}
				
				
					
				if(KeyNum==12)
				{
					
					PassWord=0;
					count=0;
LCD_ShowNum(2,1,PassWord,4);   //更新显示
		}
}
}
}